package vip.zhonghui.www.skills

import android.app.ProgressDialog
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Button
import android.widget.CheckBox
import android.widget.EditText
import android.widget.Toast
import com.google.gson.Gson
import org.json.JSONObject

class ActivityRegister : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_register)
        val username = findViewById<EditText>(R.id.username)
        val password = findViewById<EditText>(R.id.password)
        val register = findViewById<Button>(R.id.register)




        register.setOnClickListener {
            val load = ProgressDialog.show(this,"","loading...",true,false)
            load.show()

            Http.post("register", JSONObject().apply {
                put("username", username.text.toString())
                put("password", password.text.toString())
            }) { res ->
                val data = Gson().fromJson(res, Data::class.java)
                runOnUiThread {
                    if (data.data.verifySuccess) {                        load.hide()

                        Toast.makeText(
                            this,
                            "注册成功",
                            Toast.LENGTH_SHORT
                        ).show()
                        finish()
                    } else {                        load.hide()

                        Toast.makeText(this, "注册失败", Toast.LENGTH_SHORT).show()
                    }
                }
            }

        }

    }
    data class Data(
        val `data`:data2
    )
    data class data2(
        val verifySuccess:Boolean,
    )

}